import { _decorator, Component, Node, Label, director } from 'cc';
import { SSS_AudioManager } from 'db://assets/Script/Manager/SSS_AudioManager';
import { DaoShuiPaiXu_GameStorage } from '../Data/DaoShuiPaiXu_GameStorage';
import { DaoShuiPaiXu_GameData } from '../Data/DaoShuiPaiXu_GameData';
import { SSS_Consts } from 'db://assets/Script/Data/SSS_Consts';

const { ccclass, property } = _decorator;

@ccclass('DaoShuiPaiXu_Main_Scene')
export default class DaoShuiPaiXu_Main_Scene extends Component {
    public static Instance: DaoShuiPaiXu_Main_Scene;
    @property(Node)
    public Button_back: Node | null = null;
    @property(Node)
    public Button_mode_1: Node | null = null;
    @property(Node)
    public Button_mode_2: Node | null = null;
    // @property(Node)
    // public Button_5x5: Node | null = null;
    @property(Label)
    public Label_level_mode_1: Label | null = null;
    @property(Label)
    public Label_level_mode_2: Label | null = null;
    // @property(Label)
    // public Label_high_score_5x5: Label | null = null;
    onLoad() {
        DaoShuiPaiXu_Main_Scene.Instance = this;

        DaoShuiPaiXu_GameStorage.initData();
        this.ShowOn();
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();
    }
    ShowOff() {
        this.node.destroy();
        this.RemoveListener();
    }
    Refresh() {
        this.Label_level_mode_1.string = `第${DaoShuiPaiXu_GameStorage.data[`mode_1`].level}关`;
        this.Label_level_mode_2.string = `第${DaoShuiPaiXu_GameStorage.data[`mode_2`].level}关`;
    }
    AddListener() {
        this.Button_back.on(Node.EventType.TOUCH_END, this.On_Button_back, this);

        this.Button_mode_1.on(Node.EventType.TOUCH_END, this.On_Button_mode_1, this);
        this.Button_mode_2.on(Node.EventType.TOUCH_END, this.On_Button_mode_2, this);
        // this.Button_mode_3.on(Node.EventType.TOUCH_END, this.On_Button_mode_3, this);
    }
    RemoveListener() {
        this.Button_back.off(Node.EventType.TOUCH_END, this.On_Button_back, this);

        this.Button_mode_1.off(Node.EventType.TOUCH_END, this.On_Button_mode_1, this);
        this.Button_mode_2.off(Node.EventType.TOUCH_END, this.On_Button_mode_2, this);
        // this.Button_mode_3.off(Node.EventType.TOUCH_END, this.On_Button_mode_3, this);
    }
    On_Button_back() {
        console.log("On_Button_back---");
        this.ShowOff();
        director.loadScene(SSS_Consts.SceneName.MainScene);

        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_mode_1() {
        console.log("On_Button_mode_1---");

        DaoShuiPaiXu_GameData.Game_mode = `mode_1`;

        director.loadScene(SSS_Consts.SceneName.DaoShuiPaiXu_Game_Scene);
        SSS_AudioManager.PlayButtonAudio();
    }
    async On_Button_mode_2() {
        console.log("On_Button_mode_2---");

        DaoShuiPaiXu_GameData.Game_mode = `mode_2`;

        director.loadScene(SSS_Consts.SceneName.DaoShuiPaiXu_Game_Scene);
        SSS_AudioManager.PlayButtonAudio();
    }
    // async On_Button_mode_3() {
    //     console.log("On_Button_mode_3---");

    //     DaoShuiPaiXu_GameData.Game_mode = `mode_5x5`;

    //     director.loadScene(SSS_Consts.SceneName.DaoShuiPaiXu_Game_Scene);

    //     SSS_AudioManager.PlayButtonAudio();
    // }
}